// @Author miaoqing
// @Date 2024/03/28 16:23:00
// @Desc
package logic

import (
	"core/command"
	"core/component/logger"
)

func (rm *Room) joinRoomHandler(msgID uint16, data []byte) {
}

func (rm *Room) exitRoomHandler(msgID uint16, data []byte) {
}

func (rm *Room) joinGameHandler(msgID uint16, data []byte) {
	if rm.game == nil {
		return
	}
	//rm.game.joinGame()
}

func (rm *Room) exitGameHandler(msgID uint16, data []byte) {
	if rm.game == nil {
		return
	}
	//rm.game.leaveGame()

}

func (rm *Room) readyGameHandler(msgID uint16, data []byte) {
	if rm.game == nil {
		return
	}
	//rm.game.doReady()
}

func (rm *Room) startGameHandler(msgID uint16, data []byte) {
	if rm.game == nil {
		return
	}
	rm.game.doStart()
}

func (rm *Room) inputFrameHandler(msgID uint16, data []byte) {
	msgRecv := &command.CSInputFrameInfo{}
	err := rm.router.UnMarshal(data, msgRecv)
	if err != nil {
		logger.Errorf("recv data:%v msg:%v", data, msgRecv)
		return
	}
	if rm.game == nil {
		return
	}
	player := rm.game.getGamePlayer(msgRecv.PlayerID)
	if player == nil {
		return
	}
	rm.game.pushInput(player, msgRecv)
	// 下一帧强制广播(客户端要求)
	rm.game.dirty = true
}
